<script setup>
import iconNames from "@views/system/menu/components/iconNames.js";
import icon from "@utils/icon";

const filteredIconNames = (name) => {
  const match = name.match(/^([A-Z][a-z]+)/);
  return match ? match[1] : name;
};

const emit = defineEmits(["select"]);

const selectIcon = (data) => {
  emit("select", data);
};
</script>

<template>
  <div class="icon-select">
    <div
      class="icon-item"
      v-for="iconName in iconNames"
      :key="iconName"
      @click="selectIcon(iconName)"
    >
      <icon :type="iconName" style="font-size: 14px" />
      <span>{{ filteredIconNames(iconName) }}</span>
    </div>
  </div>
</template>

<style scoped lang="scss">
.icon-select {
  width: 400px;
  height: 250px;
  font-size: 12px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;

  .icon-item {
    line-height: 20px;
    width: 100px;
    border-radius: 5px;
    background: #f3f3f3;
    cursor: pointer;
    margin: 3px 0;
    padding: 2px;

    span {
      margin-left: 5px;
    }
  }
}
</style>
